<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <include file="./Public/Tpl/head.html" title="入库管理" description="药品管理系统." keywords="中南民族大学,药品管理系统"/>
</head>
<body>
<include file="./Public/Tpl/nav.html"/>
<div class="container">
  <div class="col-md-2">
    <div class="panel panel-default">
      <div class="panel-heading">功能</div>
      <div class="list-group list-menu">
        <button type="button" class="list-group-item list-menu active" data-to="0">药品入库</button>
        <button type="button" class="list-group-item list-menu" data-to="1" onclick="loadList(size,page)">入库记录</button>
      </div>
    </div>
  </div>
  <div class="col-md-10">
    <div class="panel panel-default func">
      <div class="panel-heading" style="text-align: center">药品入库</div>
      <!--<div class="panel-body text-info">首先输入拼音码,确认药品存在后才能执行入库操作</div>-->
      <div class="panel-body text-info"></div>
      <form id="storageForm" class="form-horizontal" target="_blank" action="{:U('Storage/doAdd')}">
        <div class="col-md-6">
          <div class="form-group">
            <label for="inputPinyin" class="col-sm-3 control-label">拼音码</label>
            <div class="col-sm-9" data-toggle="tooltip" data-placement="top" title="输入拼音码自动获取药品信息">
              <input name="pinyinma" type="text" class="form-control" id="inputPinyin" placeholder="拼音码"
                     autocomplete="off">
            </div>
          </div>
          <div class="form-group">
            <label for="inputPihao" class="col-sm-3 control-label">批号</label>
            <div class="col-sm-9">
              <input name="pihao" type="text" class="form-control" id="inputPihao" placeholder="药品批号">
            </div>
          </div>
          <div class="form-group">
            <label for="inputPizhunwenhao" class="col-sm-3 control-label">批准文号</label>
            <div class="col-sm-9">
              <input name="pizhunwenhao" type="text" class="form-control" id="inputPizhunwenhao" placeholder="药品批准文号">
            </div>
          </div>
          <div class="form-group">
            <label for="inputAmount" class="col-sm-3 control-label">进货数量</label>
            <div class="col-sm-9">
              <input name="storage_amount" type="text" width="10" class="form-control" id="inputAmount" placeholder="0">
            </div>
          </div>
          <div class="form-group">
            <label for="inputPrice" class="col-sm-3 control-label">进货单价</label>
            <div class="col-sm-9">
              <input name="inprice" type="text" class="form-control" id="inputPrice" placeholder="0.00">
            </div>
          </div>
          <div class="form-group">
            <label for="inputAllprice" class="col-sm-3 control-label">进货总额</label>
            <div class="col-sm-9">
              <input name="allprice" type="text" class="form-control" id="inputAllprice" placeholder="0.00">
            </div>
          </div>
          <div class="form-group">
            <label for="inputTime" class="col-sm-3 control-label">进货时间</label>
            <div class="col-sm-9 input-append date form_datetime">
              <input name="in_time" type="text" class="form-control" id="inputTime" value="{:date('Y/m/d',time())}"
                     readonly placeholder="点击选择">
              <span class="add-on"><i class="icon-th"></i></span>
            </div>
          </div>
          <div class="form-group">
            <label for="inputFrom" class="col-sm-3 control-label">进货单位</label>
            <div class="col-sm-9">
              <input name="in_from" type="text" class="form-control" id="inputFrom" placeholder="0">
            </div>
          </div>

        </div>
        <div class="col-md-6">
          <div class="form-group">
            <label for="inputName" class="col-sm-3 control-label">名称</label>
            <div class="col-sm-9">
              <input name="name" type="text" class="form-control" readonly id="inputName" placeholder="药品名称">
            </div>
          </div>
          <div class="form-group">
            <label for="inputSpec" class="col-sm-3 control-label">规格大小</label>
            <div class="col-sm-9">
              <input name="spec" type="text" class="form-control" disabled id="inputSpec" placeholder="规格">
            </div>
          </div>
          <div class="form-group">
            <label for="inputUnit" class="col-sm-3 control-label">计量单位</label>
            <div class="col-sm-9">
              <input name="unit" type="text" class="form-control" disabled id="inputUnit" placeholder="单位">
            </div>
          </div>
          <div class="form-group">
            <label for="inputLowwarning" class="col-sm-3 control-label">库存低限</label>
            <div class="col-sm-9">
              <input name="lowwarning" type="text" class="form-control" disabled id="inputLowwarning"
                     placeholder="最低库存保存">
            </div>
          </div>
          <div class="form-group">
            <label for="inputFactory" class="col-sm-3 control-label">生产厂家</label>
            <div class="col-sm-9">
              <input name="factory" type="text" class="form-control" id="inputFactory" placeholder="请输入">
            </div>
          </div>
          <div class="form-group">
            <label for="inputProduceDate" class="col-sm-3 control-label">生产日期</label>
            <div class="col-sm-9 input-append date form_datetime">
              <input name="producedate" type="text" class="form-control" id="inputProduceDate" readonly
                     placeholder="点击选择">
              <span class="add-on"><i class="icon-th"></i></span>
            </div>
          </div>
          <div class="form-group">
            <label for="inputUsefulDate" class="col-sm-3 control-label">失效日期</label>
            <div class="col-sm-9 input-append date form_datetime">
              <input name="usefuldate" type="text" class="form-control" id="inputUsefulDate" readonly
                     placeholder="点击选择">
              <span class="add-on"><i class="icon-th"></i></span>
            </div>
          </div>
          <div class="form-group">
            <label for="inputRemark" class="col-sm-3 control-label">备注</label>
            <div class="col-sm-9">
              <input name="remark" type="text" class="form-control" id="inputRemark" placeholder="无">
            </div>
          </div>
        </div>
        <div class="form-group">
          <div class="col-sm-offset-2 col-sm-9">
            <button id="doStorage" type="button" class="btn btn-success submit">入库</button>
            <button type="reset" class="btn btn-warning">清空</button>
          </div>
        </div>
      </form>
    </div>
    <div class="panel panel-default func" id="storageList">
      <div class="panel-heading" style="text-align: center">入库记录</div>
      <table class="table table-hover">
        <thead>
        <tr>
          <th>编号</th>
          <th>药品名称</th>
          <th>批号</th>
          <th>批准文号</th>
          <th>数量</th>
          <th>进货单价</th>
          <th>总额</th>
          <th>进货时间</th>
          <th>进货单位</th>
          <th>生产厂家</th>
          <th>生产日期</th>
          <th>到期</th>
          <th>操作员</th>
          <th>备注</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="info in list">
          <td>{{ info.storage_id }}</td>
          <td>{{ info.name }}</td>
          <td>{{ info.pihao }}</td>
          <td>{{ info.pizhunwenhao }}</td>
          <td>{{ info.storage_amount }}</td>
          <td>{{ info.inprice }}</td>
          <td>{{ info.allprice }}</td>
          <td>{{ info.in_time }}</td>
          <td>{{ info.in_from }}</td>
          <td>{{ info.factory }}</td>
          <td>{{ info.producedate }}</td>
          <td>{{ info.usefuldate }}</td>
          <td>{{ info.realname }}</td>
          <td>{{ info.remark }}</td>
        </tr>
        </tbody>
      </table>
      <div id="storagePage" class="center">
        <nav>
          <ul class="pagination">
            <li v-for="i in count">
              <a href="javascript:" :data-to="i">{{ i }}</a>
            </li>
          </ul>
        </nav>
      </div>
    </div>
  </div>
</div>
<include file="./Public/Tpl/footer.html"/>
<js href="__PUBLIC__/js/jquery.Kcomplete-1.1.min.js"/>
<script>
    var size = 10;
    var page = 1;
    var storageList = {list: [], count: 10};
    var app = new Vue({
        el: '#storageList',
        data: storageList
    });
    function loadList(size, page) {
        $.ajax({
            type: 'POST',
            url: "{:U('Storage/getStorageRecord')}",
            data: {"size": size, "page": page},
            dataType: 'json',
            async:false,
            success: function (rs) {
                if (rs.code == 200) {
                    storageList.list = rs.data.list;
                    storageList.count = Math.ceil(rs.data.count/size);
                }
            },
            beforeSend: function () {
                this.layerIndex = layer.load(1, {shade: [0.8, '#393D49'],time:1000});
            },
            complete: function () {
                layer.close(this.layerIndex);
            }
        });
    }
    function fillTotalMoney() {
        var amount = $("#inputAmount").val();
        var price = $("#inputPrice").val();
        if (amount != "" && price != "") {
            $("#inputAllprice").attr("value", (amount * price).toFixed(2));
        }
    }
    //总价集成
    $(document).on("keyup", "#inputPrice,#inputAmount", function () {
        fillTotalMoney();
    });
    $(document).ready(function () {
        //加载更多
        layui.use(['laypage', 'layer'], function () {
            loadList(size,page);
            layer = layui.layer;
            laypage = layui.laypage;
            laypage({
                cont: 'storagePage'
                , pages: storageList.count
                , skin: '#337ab7'
                , skip: true,
                jump: function (obj, first) {
                    if (!first) {
                        page = obj.curr;
                        loadList(size, page);
                    }
                }
            });
        });

        //提交入库
        $("#doStorage").click(function () {
            $.ajax({
                url: "{:U('Storage/doAdd')}",
                data: $("#storageForm").serialize(),
                dataType: "json",
                type: "POST",
                beforeSend: function () {
                    this.layerIndex = layer.load(1,{ shade: [0.1, '#393D49'] });
                },
                success: function (data) {
                    if (data['code'] == 200) {
                        layer.msg("入库成功!",{icon:1});
                    } else {
                        layer.msg("原因:" + data['msg'],{icon:2});
                    }
                },
                error: function () {
                    layer.msg("提交过程中发生问题! ",{icon:0});
                },
                complete:function(){
                    layer.close(this.layerIndex);
                }
            })
        });
        //拼音码自动提示
        $("#inputPinyin").Kcomplete({
            location: "{:U('Drug/nameTips')}",
            dataType: 'json'
        });
        //公司自动提示
        $("#inputFactory").Kcomplete({
            location: "{:U('Company/nameTips')}",
            dataType: 'json'
        });
        //拼音码事件
        $("#inputPinyin").bind("keyup change", function () {
            if ($(this).val() == '') return;
            if(sessionStorage.getItem("22")){
                console.log(111111);
            }
            $.ajax({
                url: "{:U('Drug/getInfo')}",
                data: "pinyinma=" + $("#inputPinyin").val(),
                dataType: "json",
                type: "get",
                success: function (data) {
                    console.log(data['code'] + " " + data.msg);
                    if (data['code'] == 200) {
                        var tempName = data.data.name;
                        var tempSpec = data.data.spec;
                        var tempUnit = data.data.unit;
                        var tempLowwarning = data.data.lowwarning;
                    } else {
                        var tempName = data.msg;
                        var tempSpec = data.msg;
                        var tempUnit = data.msg;
                        var tempLowwarning = data.msg;
                    }
                    $("#inputName").attr("value", tempName);
                    $("#inputSpec").attr("value", tempSpec);
                    $("#inputUnit").attr("value", tempUnit);
                    $("#inputLowwarning").attr("value", tempLowwarning);
                },
                error: function () {
                },
            })
        });
    });
</script>
</body>
</html>